package com.yy.controller;


import com.yy.common.annotation.Log;
import com.yy.common.core.controller.BaseController;
import com.yy.common.core.domain.AjaxResult;

import com.yy.common.core.page.TableDataInfo;
import com.yy.common.enums.BusinessType;
import com.yy.common.utils.poi.ExcelUtil;
import com.yy.domain.ParkDevice;
import com.yy.service.ParkDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.yy.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/park/device")
public class ParkDeviceController extends BaseController{
    @Autowired
    private ParkDeviceService parkDeviceService;

    /**
     * 查询匝道设备列表
     * @param parkDevice
     * @return
     */
    @PreAuthorize("@ss.hasPermi('park:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkDevice parkDevice){
        startPage();
        List<ParkDevice> list=parkDeviceService.selectParkDeviceList(parkDevice);
        return getDataTable(list);
    }

    /**
     * 导出匝道设备列表
     * @param response
     * @param parkDevice
     */
    @PreAuthorize("@ss.hasPermi('park:device:export')")
    @Log(title = "匝道设备管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,ParkDevice parkDevice){
        List<ParkDevice> list=parkDeviceService.selectParkDeviceList(parkDevice);
        ExcelUtil<ParkDevice> util=new ExcelUtil<>(ParkDevice.class);
        util.exportExcel(response,list,"匝道设备管理数据");
    }

    /**
     * 获取匝道设备详细信息
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('park:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return success(parkDeviceService.selectParkDeviceById(id));
    }

    /**
     * 添加匝道设备
     * @param parkDevice
     * @return
     */
    @PreAuthorize("@ss.hasPermi('park:device:add')")
    @Log(title = "匝道设备管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ParkDevice parkDevice){
        return toAjax(parkDeviceService.insertParkDevice(parkDevice));
    }

    /**
     * 修改匝道设备管理
     */
    @PreAuthorize("@ss.hasPermi('park:device:edit')")
    @Log(title = "匝道设备管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkDevice parkDevice)
    {
        return toAjax(parkDeviceService.updateParkDevice(parkDevice));
    }

    /**
     * 批量删除匝道设备管理
     */
    @PreAuthorize("@ss.hasPermi('park:device:remove')")
    @Log(title = "匝道设备管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(parkDeviceService.deleteParkDeviceByIds(ids));
    }

}
